from django.shortcuts import render
from django.views import View
from collections import OrderedDict
from contents.utils import get_categories
from contents.models import ContentCategory,Content
from goods.models import GoodsChannelGroup, GoodsChannel,GoodsCategory
# Create your views here.





class IndexView(View):
    '''首页广告'''
    def get(self,request):
        categories = get_categories()
        contents = OrderedDict()
        # #查询广告类别
        content_categories =ContentCategory.objects.all()
        for content_categorie in content_categories:
            contents[content_categorie.key] = content_categorie.content_set.filter(status=True).order_by('sequence')

        #构造上下文
        context = {
            'categories':categories,
            'contents':contents
        }
        return render(request, 'index.html',context)










